<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title><bean:message bundle="UsuarioResources" key="jsp.title.cadastrar"/></title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="">

	<link rel="stylesheet" type="text/css" href="../extjs/layout-browser.css">
	<link rel="stylesheet" type="text/css" href="../css/basic.css">
	<link rel="stylesheet" type="text/css" href="../extjs/ext-all.css">

	<script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../extjs/ext-base.js"></script>
    <script type="text/javascript" src="../extjs/ext-all.js"></script>
	<script type="text/javascript" src="../extjs/examples.js"></script>
	<script type="text/javascript" src="../js/util.js"></script>
	<script type="text/javascript" src="../js/masks.js"></script>

	<script type="text/javascript" language="JavaScript">
		function cadastrar() {
			if (document.forms[0].apelido.value == "") {
				alertMsg("Apelido", "Apelido n&atilde;o informado!", document.forms[0].apelido);
				return false;
			}

			if (document.forms[0].senha.value == "" || document.forms[0].confirmaSenha.value == "") {
				alertMsg("Senha", "Senha n&atilde;o informada!", document.forms[0].senha);
				return false;
			}

			if (document.forms[0].senha.value != document.forms[0].confirmaSenha.value) {
				alertMsg("Senha", "Senha n&atilde;o confere!", document.forms[0].senha);
				return false;
			}

			if (document.forms[0].cep.value == "" || document.forms[0].cep.length < 8) {
				alertMsg("CEP", "CEP inv&atilde;lido!", document.forms[0].cep);
				return false;
			}

			document.forms[0].submit();
			return true;
		}
	</script>
  </head>
 
  <body>
  <div id="header"><h1><bean:message key="jsp.system.title"/></h1></div>
  <br>
  <logic:notPresent name="usuarioDTO">
    <html:form action="/Usuario/CadastrarUsuario.do" method="POST" focus="apelido">
      <table border="0">
      	<logic:present name="apelidoInvalido">
	        <tr>
	          <td colspan="2" style="color: red;" align="center"><bean:message bundle="UsuarioResources" key="jsp.alert.apelidoIndisponivel"/></td>
	        </tr>
        </logic:present>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.apelido"/><font style="color: red;">*</font>:</td>
          <td><html:text property="apelido" size="15" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.nome"/>:</td>
          <td><html:text property="nome" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.email"/>:</td>
          <td><html:text property="email" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.endereco"/>:</td>
          <td><html:text property="endereco" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.cep"/><font style="color: red;">*</font>:</td>
          <td><html:text styleId="cep" property="cep" size="10" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.telefone"/>:</td>
          <td><html:text styleId="telefone" property="telefone" size="15" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.senha"/><font style="color: red;">*</font>:</td>
          <td><html:password property="senha" size="10" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.confirmaSenha"/><font style="color: red;">*</font>:</td>
          <td><html:password property="confirmaSenha" size="10" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.dataNascimento"/>:</td>
          <td><html:text styleId="dataNascimento" property="dataNascimento" size="10" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="center">
          	<br>
          	<html:button property="btnCadastrar" value="Cadastrar" onclick="return cadastrar();"/>
          </td>
        </tr>
      </table>
    </html:form>
</logic:notPresent>

<logic:present name="usuarioDTO">
      <table border="0">
		<tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.apelido"/>:</td>
          <td><bean:write name="usuarioDTO" property="apelido"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.nome"/>:</td>
          <td><bean:write name="usuarioDTO" property="nome"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.email"/>:</td>
          <td><bean:write name="usuarioDTO" property="email"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.endereco"/>:</td>
          <td><bean:write name="usuarioDTO" property="endereco"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.cep"/>:</td>
          <td><bean:write name="usuarioDTO" property="cep"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.telefone"/>:</td>
          <td><bean:write name="usuarioDTO" property="telefone"/></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.dataNascimento"/>:</td>
          <td><logic:present name="usuarioDTO" property="dataNascimento">
          		<bean:write name="usuarioDTO" property="dataNascimento" format="dd/MM/yyyy"/>
          	  </logic:present>
          </td>
        </tr>
      </table>
</logic:present>

<br/><br/>
<a href="../Login/PrepareLogin.do">Voltar</a>

<script language="JavaScript" type="text/javascript">
	var dateMask = new Mask("dd/mm/yyyy", "date");
	dateMask.attach(document.getElementById("dataNascimento"));

	var telMask = new Mask("(##) ####-####");
	telMask.attach(document.getElementById("telefone"));

	var cepMask = new Mask("#####-###");
	cepMask.attach(document.getElementById("cep"));
</script>
  </body>
</html:html>
